"""
@Project : pythonExample
@File    : 元编程.py
@IDE     : PyCharm
@Author  : RR9
@Date    : 2024/08/27 17:38
@Explain :
"""

"""装饰器

"""

from functools import wraps
import time


def log_level(level):
    def out_func(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            print('wrapper函数开始计算')
            start = time.time()
            result = func(*args, **kwargs)
            end = time.time()
            print(f"""{level}:函数{func.__name__} 执行了{end - start} 秒""")
            return result
        return wrapper
    return out_func


@log_level("INFO")
def add(*args):
    """
    一个任意个数的数相加，返回相加相加之和
    :param args:
    :return:
    """
    print('add函数开始计算')
    time.sleep(2)
    return sum(args)


@log_level("DEBUG")
def add2(*args):
    """
    add2 任意个数的数相加
    :param args:
    :return:
    """
    print('add函数开始计算')
    time.sleep(2)
    return sum(args)
